# 脚本=>同步历史数据(西医/中医治疗)

import math

from django.core.management.base import BaseCommand
from prj003.models.cure import Cure
from prj003.utils.constants import DICT_IS_XIYI, DICT_IS_ZHONGYI


class Command(BaseCommand):
    help = '同步数据'

    def add_arguments(self, parser):
        pass

    def handle(self, *args, **options):
        cure_count = Cure.objects.count()
        PAGE_SIZE = 3
        pages_nums = math.ceil(cure_count / PAGE_SIZE)

        for num in range(0, pages_nums):
            cure_objs = Cure.objects.all().order_by('-id')[(num*PAGE_SIZE):((num+1)*PAGE_SIZE)]
            for obj in cure_objs:
                for val in DICT_IS_XIYI.keys():
                    if getattr(obj, val):
                        obj.is_xiyi = True
                        break

                for val in DICT_IS_ZHONGYI.keys():
                    if getattr(obj, val):
                        obj.is_zhongyi = True
                        break

                obj.save()
                print('{}----设定分类完毕---'.format(obj.info.id))
